package com.zemb.flxwear.Adapter;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.zemb.flxwear.Bean.ReportItem;
import com.zemb.flxwear.R;

import java.util.ArrayList;
import java.util.List;

public class ReportAdapter extends RecyclerView.Adapter<ReportAdapter.ViewHolder>  {
    private List<ReportItem> list;
    private Context context;
    public ReportAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    @NonNull
    @Override
    public ReportAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_report, viewGroup, false);
        ReportAdapter.ViewHolder viewHolder = new ReportAdapter.ViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ReportAdapter.ViewHolder viewHolder, int position) {
        ReportItem reportItem = list.get(position);
        switch (reportItem.type){
            case BLOOD_SUGAR:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.blood_sugar_green));
                break;
            case BLOOD_PRESSURE:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.blood_pressure_green));
                break;
            case BLOOD_OXYGEN:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.blood_oxygen_green));
                break;
            case ECG:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.pulse_green));
                break;
            case URIC_ACID:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.uric_acid_green));
                break;
            case CHOLESTEROL:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.cholesterol_green));
                break;
            case BLOOD_KETONE:
                viewHolder.iv_hp.setImageDrawable(context.getResources().getDrawable(R.mipmap.static_blood_pressure_green));
                break;
        }


        viewHolder.tv_result.setText(String.valueOf(reportItem.getResult()));
        viewHolder.tv_time.setText(reportItem.getTime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setList(List<ReportItem> list) {
        this.list = list;
        notifyDataSetChanged();
    }
class ViewHolder extends RecyclerView.ViewHolder {
    //这些控件都可以设置监听事件
    private TextView tv_result, tv_time;
    private ImageView iv_hp;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        tv_result = itemView.findViewById(R.id.tv_report_data);
        tv_time = itemView.findViewById(R.id.tv_time);
        iv_hp = itemView.findViewById(R.id.iv_hp);


    }
}

}
